#ifndef __GAMESCENE_LAYER_H__
#define __GAMESCENE_LAYER_H__
#include "cocos2d.h"
#include "FoodSprite.h"

USING_NS_CC;

#define frandom_range(low,high) ((high-low)*CCRANDOM_0_1())+low
#define random_range(low,high) (rand()%(high-low+1))+low

#define midpoint(a, b) (float)(a + b)/2

typedef enum _TossType
{
	kTossConsecutive = 0,
	kTossSimultaneous
}TossType;

class GameLayer:public CCLayer
{
public:
	~GameLayer();
	virtual bool init();  
	static cocos2d::CCScene* scene(int id);
	static GameLayer* sharedGameLayer();

	void restart();
	void changeSpeed(bool isdoubleSpeed);

	void  addScore(int score);
	void  updateState(PlayerState state);
	void  updateStateCallback(float cctime);

	CREATE_FUNC(GameLayer);

	//virtual void onExit();
	FoodPlayer *player;
};


class GSpriteLayer:public CCLayer
{
public:
	virtual bool init();  
	~GSpriteLayer(void);

	void resetFoodSprite();

	void foodSpritesUpdata(float cctime);

	void spriteLoop();

	void changeSpeed(bool isdoubleSpeed);

	void tossSprite(FoodSprite* sprite);

	void runSpritesMoveSequence(CCSprite* pfood);
	void spriteDidDropCallback(CCNode * obj);
	void spriteAwayCallback(CCNode * obj);

	CREATE_FUNC(GSpriteLayer);


	long millisecondNow(){
		cocos2d::cc_timeval now;
		cocos2d::CCTime::gettimeofdayCocos2d(&now, NULL);
		return (now.tv_sec * 1000 + now.tv_usec / 1000);
		//return now.tv_usec;
	}
};


class GPauseLayer:public CCLayer
{
public:
	
	virtual bool init();  
	void menuPauseCallback(CCObject* pSender);
	void menuRestartCallback(CCObject* pSender);

	CREATE_FUNC(GPauseLayer);

};

class GScoreLayer:public CCLayer
{
public:
	virtual bool init();  
	void step(float dt);
	int score;

	CREATE_FUNC(GScoreLayer);

};

class GItemLayer:public CCLayer
{
public:
	GItemLayer();
	virtual bool init();  
	virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
	virtual void ccTouchesBegan(CCSet *pTouch, CCEvent *pEvent);
	virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);

	CREATE_FUNC(GItemLayer);

};
#endif